package com.javaclimb.drug.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.javaclimb.drug.common.ResultMapUtil;
import com.javaclimb.drug.entity.Returnsupplier;
import com.javaclimb.drug.service.IReturnsupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName UserController.java
 * @Description TODO 退货给供应商相关的controller
 * @createTime 2021年10月02日 09:05:00
 */

@Controller
@RequestMapping(value = "/returnsupplier")
public class ReturnsupplierController {
    @Autowired
    private IReturnsupplierService iReturnsupplierService;


    /**
     * 转向退货给供应商页面
     * @return
     */
    @RequestMapping
    public String login(){
        return "/returnsupplier";
    }

    /**
     * 分页查询退货给供应商列表
     * @return
     */
    @RequestMapping(value = "/returnsupplierQueryPage")
    @ResponseBody
    public HashMap<String, Object> returnsupplierQueryPage(String param, @RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit) {
        try {
            IPage<Returnsupplier> iPage = iReturnsupplierService.selectReturnsupplierPage(page, limit, param);
            return ResultMapUtil.getHashMapMysqlPage(iPage);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 转向退货给供应商新增页面
     * @return
     */
    @RequestMapping(value = "/returnsupplierPage")
    public String returnsupplierPage(){
        return "/returnsupplierPage";
    }

    /**
     * 添加一个退货给供应商
     * @return
     */
    @RequestMapping(value = "/returnsupplierAdd")
    @ResponseBody
    public Object returnsupplierAdd(Returnsupplier returnsupplier){
        try {
//            returnsupplier(new Date());
            int i = iReturnsupplierService.addReturnsupplier(returnsupplier);

            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 转向退货给供应商编辑页面
     * @return
     */
    @RequestMapping(value = "/returnsupplierQueryById")
    public String returnsupplierQueryById(@RequestParam(name = "id",required = true) Integer id, Model model){
        Returnsupplier returnsupplier = iReturnsupplierService.queryReturnsupplierById(id);
        model.addAttribute("obj",returnsupplier);

        return "/returnsupplierPage";
    }
    /**
     * 修改一个退货给供应商
     * @return
     */
    @RequestMapping(value = "/returnsupplierEdit")
    @ResponseBody
    public Object returnsupplierEdit(Returnsupplier returnsupplier){
        try {
            int i = iReturnsupplierService.editReturnsupplier(returnsupplier);

            return ResultMapUtil.getHashMapSave(i);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }
    /**
     * 删除一个退货给供应商
     * @return
     */
    @RequestMapping(value = "/returnsupplierDelById")
    @ResponseBody
    public Object returnsupplierDelById(Integer id){
        try {
            int i = iReturnsupplierService.delReturnsupplierById(id);

            return ResultMapUtil.getHashMapDel(i);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }

}
